﻿using Halcon二次开发.Model.自定义控件;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 可视化工具.View.Csv文件;

namespace 可视化工具.View.重命名界面
{
    public partial class ChongmingminForm : Form
    {
        HwindowFlowNodeUrseControl hwindowFlowNode;
        string text;
        public ChongmingminForm(HwindowFlowNodeUrseControl hwindowFlowNode,string text)
        {
            InitializeComponent();
            this.hwindowFlowNode = hwindowFlowNode;
            this.text = text;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TabPage tabPage = null;
            foreach (TabPage item in hwindowFlowNode.csvMainForm.uiTabControlMenu1.TabPages)
            {
                if (item.Text == text)
                {
                    tabPage = item;
                }
            }

            string name = "";
            if (text.Contains("模型匹配"))
            {
                int charIndex = text.IndexOf('配');
                if (text.Contains('-'))
                {
                    name = text.Substring(charIndex + 1, text.IndexOf('-') + 1 - charIndex - 2);
                }
                else
                {
                    name = text.Substring(charIndex + 1, text.Length - charIndex - 1);
                }
            }
            else if (text.Contains("测量模块"))
            {
                int charIndex = text.IndexOf('具');
                if (text.Contains('-'))
                {
                    name = text.Substring(charIndex + 1, text.IndexOf('-') + 1 - charIndex - 2);
                }
                else
                {
                    name = text.Substring(charIndex + 1, text.Length - charIndex - 1);
                }
            }


            if (tabPage == null) return;
            if (tabPage.Controls[0] is CsvModelForm m)
            {
                m.button1_Click(null, null);
                m.textBox模板.Text = name + "-" + textBox1.Text.Trim(); ;
                m.button2_Click(null, null);
            }
            else if (tabPage.Controls[0] is CsvCailperForm_ c)
            {

                c.btn模块工具_Click(null, null);
                c.textBox模块工具.Text = name + "-" + textBox1.Text.Trim();
                c.btn模块工具1_Click(null, null);

            }
            this.Close();
        }
    }
}
